package com.yz.lzq.liwushuo.adapter;

import android.content.Context;
import android.graphics.Paint;
import android.net.Uri;
import android.support.v7.widget.RecyclerView;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.TextView;

import com.facebook.drawee.view.SimpleDraweeView;
import com.yz.lzq.liwushuo.R;
import com.yz.lzq.liwushuo.bean.CategroyDanPBean;

import java.util.List;

import butterknife.Bind;
import butterknife.ButterKnife;

/**
 * Created by AdminJia on 2016/11/28.
 */

public class CategoryDanPAdapter extends RecyclerView.Adapter<RecyclerView.ViewHolder> {
    private List<Object> mList_object = null;
    public static final int GROUP = 0, CHILD = 1;
    private Context mContext = null;

    public List<Object> getmList_object() {
        return mList_object;
    }

    public CategoryDanPAdapter(List<Object> mList_object, Context mContext) {
        this.mList_object = mList_object;
        this.mContext = mContext;
    }

    @Override
    public int getItemViewType(int position) {
        if (mList_object.get(position) instanceof CategroyDanPBean.DataBean.CategoriesBean) {
            return GROUP;
        }

        return CHILD;
    }

    @Override
    public RecyclerView.ViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
        View view = null;
        switch (viewType) {
            case 0:
                view = LayoutInflater.from(mContext).inflate(R.layout.item_category_danp_group,
                        parent, false);
                return new ViewHolderGroup(view);
            case 1:
                view = LayoutInflater.from(mContext).inflate(R.layout.item_category_danp_child,
                        parent, false);
                return new ViewHolderChild(view);


        }
        return null;
    }

    @Override
    public void onBindViewHolder(RecyclerView.ViewHolder holder, int position) {
        if (holder instanceof ViewHolderGroup) {
            CategroyDanPBean.DataBean.CategoriesBean categoriesBean = (CategroyDanPBean.DataBean
                    .CategoriesBean) mList_object.get(position);
            ((ViewHolderGroup) holder).textViewCategoryDanPGroupLeft.setText("           ");
            ((ViewHolderGroup) holder).textViewCategoryDanPGroupRight.setText("             ");
            ((ViewHolderGroup) holder).textViewCategoryDanPGroup.setText(categoriesBean.getName()
                    + "");

        } else if (holder instanceof ViewHolderChild) {
            CategroyDanPBean.DataBean.CategoriesBean.SubcategoriesBean subcategoriesBean =
                    (CategroyDanPBean.DataBean.CategoriesBean.SubcategoriesBean) mList_object.get
                            (position);
            ((ViewHolderChild) holder).simpleDraweeViewCategoryDanPChild.setImageURI(Uri.parse
                    (subcategoriesBean.getIcon_url() + ""));
            ((ViewHolderChild) holder).textViewCategoryDanPChild.setText(subcategoriesBean
                    .getName() + "");

        }

    }

    @Override
    public int getItemCount() {
        return mList_object.size();
    }

    class ViewHolderGroup extends RecyclerView.ViewHolder {
        @Bind(R.id.textView_category_danP_group_left)
        TextView textViewCategoryDanPGroupLeft;
        @Bind(R.id.textView_category_danP_group)
        TextView textViewCategoryDanPGroup;
        @Bind(R.id.textView_category_danP_group_right)
        TextView textViewCategoryDanPGroupRight;

        public ViewHolderGroup(View itemView) {
            super(itemView);
            ButterKnife.bind(this, itemView);
            textViewCategoryDanPGroupLeft.getPaint().setFlags(Paint.STRIKE_THRU_TEXT_FLAG);
            textViewCategoryDanPGroupRight.getPaint().setFlags(Paint.STRIKE_THRU_TEXT_FLAG);
        }
    }

    class ViewHolderChild extends RecyclerView.ViewHolder {
        @Bind(R.id.simpleDraweeView_category_danP_child)
        SimpleDraweeView simpleDraweeViewCategoryDanPChild;
        @Bind(R.id.textView_category_danP_child)
        TextView textViewCategoryDanPChild;

        public ViewHolderChild(View itemView) {
            super(itemView);
            ButterKnife.bind(this, itemView);
        }
    }


}
